<?php
session_start(); 
 if(isset($_SESSION['url']))
  unset($_SESSION['url']);
  
  $datei = $_REQUEST['id'];
 	
 
 //$imagepath=("/home/rockedg1/public_html/badge/uploads" .$datei);
 $imagepath = ($datei);
 $ext = strtolower(end(explode('.',$imagepath))); 

  //$_SESSION['url'] =  $imagepath;

//set mime type content

header('Content-Type: image/jpeg');


//create original image
switch ($ext) {
        case 'jpg':
        case 'jpeg':
                    $image = imagecreatefromjpeg($imagepath) ; 
        break;
        case 'gif':
                    $image = imagecreatefromgif($imagepath) ; 
        break;
        case 'png':
                    $image = imagecreatefrompng($imagepath) ; 
        break;
    } 
//$image = imagecreatefromjpeg($imagepath);

//get image dimension

$dim=getimagesize($imagepath);
$dimensions_of_thumb = get_dims($imagepath,'300px');

//Set thumb dimension
 //$pixelsw = 300;
// $pixelsh = 300;


$thumbw = $dimensions_of_thumb[0];
$thumbh = $dimensions_of_thumb[1];

$thumbwold = $dim[0];
$thumbhold = $dim[1];

//$thumbw = 300;
//$thumbh = 260;

//create empty image

$thumb_image=imagecreatetruecolor($thumbw, $thumbh);

//Resize original image and copy it to thumb image

imagecopyresampled($thumb_image, $image, 0, 0, 0, 0,
					$thumbw, $thumbh, $dim[0], $dim[1]);


//display thumb image
imagejpeg($thumb_image);
//imagejpeg(resizeImage($image,300,300));
imagedestroy($thumb_image);

  $_SESSION['url'] =  $imagepath;

?>
<?php
function get_dims($src_img,$new_h) {
// A small function to ensure that the width and height of the thumbnails are no larger than selected size (i.e. 300px)
$new_w=$new_h;
$size=getimagesize($src_img);
$old_x=$size[0];
$old_y=$size[1];
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$size[0]=$thumb_w;$size[1]=$thumb_h;

return $size;

} 
  
?> 
<?PHP
/* RESIZE FUNCTION */
/* the parameters */
/*
$file is the name of the original image WITHOUT the path
$save is the name of the resized image WITHOUT the path 
$t_w is the MAXIMUM width of the new image
$t_h is the MAXIMUM height of the new image
$o_path is the path to the original image INCLUDE trailing slash
$s_path is the path where you want to save the new image INCLUDE trailing slash
NOTE: to overwrite the original with the new, use the same name and path for both
*/

function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) {
    $s_path = trim($s_path);
    $o_path = trim($o_path);
    $save = $s_path . $save;
    $file = $o_path . $file;
    $ext = strtolower(end(explode('.',$save)));
    list($width, $height) = getimagesize($file) ; 
    if(($width>$t_w) OR ($height>$t_h)) {
        $r1 = $t_w/$width;
        $r2 = $t_h/$height;
        if($r1<$r2) {
          $size = $t_w/$width;
        }else{
          $size = $t_h/$height;
        }
    }else{
        $size=1;
    }
    $modwidth = $width * $size; 
    $modheight = $height * $size; 
    $tn = imagecreatetruecolor($modwidth, $modheight) ; 
    switch ($ext) {
        case 'jpg':
        case 'jpeg':
                    $image = imagecreatefromjpeg($file) ; 
        break;
        case 'gif':
                    $image = imagecreatefromgif($file) ; 
        break;
        case 'png':
                    $image = imagecreatefrompng($file) ; 
        break;
    }
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
    imagejpeg($tn, $save, 100) ; 
    return;
}
/*         END OF RESIZE FUNCTION */
?>
<?php
function browser_info($agent=null) {
  // Declare known browsers to look for
  $known = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape',
    'konqueror', 'gecko');

  // Clean up agent and build regex that matches phrases for known browsers
  // (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor
  // version numbers.  E.g. "2.0.0.6" is parsed as simply "2.0"
  $agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']);
  $pattern = '#(?<browser>' . join('|', $known) .
    ')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#';

  // Find all phrases (or return empty array if none found)
  if (!preg_match_all($pattern, $agent, $matches)) return array();

  // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase,
  // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one
  // in the UA).  That's usually the most correct.
  $i = count($matches['browser'])-1;
  return array($matches['browser'][$i] => $matches['version'][$i]);
}
?>

